import { CuboidCollider, RigidBody } from "@react-three/rapier";
import { sharedBoxGeometry } from "../../../../common/geometry/geometry.js";
import { shadedWallMaterial } from "../../../../common/material/material.js";

/**
 *
 * 墙体
 *
 */

function Bounds({ length = 1 }) {
  return (
    <>
      <group>
        <RigidBody type="fixed" restitution={0.2} friction={0}>
          {/* 右侧墙体 */}
          <mesh
            position={[2.15, 0.75, -((length * 4) / 2) + 2]}
            scale={[0.3, 1.5, 4 * length]}
            geometry={sharedBoxGeometry}
            material={shadedWallMaterial}
            receiveShadow
          ></mesh>
          {/* 左侧墙体 */}
          <mesh
            position={[-2.15, 0.75, -((length * 4) / 2) + 2]}
            scale={[0.3, 1.5, 4 * length]}
            geometry={sharedBoxGeometry}
            material={shadedWallMaterial}
            receiveShadow
          ></mesh>
          {/* 终点墙体 */}
          <mesh
            position={[0, 0.75, -((length - 1) * 4 + 2)]}
            scale={[4, 1.5, 0.3]}
            geometry={sharedBoxGeometry}
            material={shadedWallMaterial}
            receiveShadow
          ></mesh>
          {/* 地面的碰撞体 */}
          <CuboidCollider
            args={[2, 0.1, 2 * length]}
            position={[0, -0.1, -2 * length + 2]}
            // 这里摩擦力设置为1，球体滚动时就会向前运动
            // 如果设置为0，玩家操控的球体就会原地打滑
            friction={1}
          />
        </RigidBody>
      </group>
    </>
  );
}

export default Bounds;


    